import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;

/**
 * Created by loso on 2017/3/17.
 */
public class _38_CountAndSay {

    public static void main(String[] args) {
_38_CountAndSay a = new _38_CountAndSay();
        System.out.println(a.countAndSay(3));
    }

    public String countAndSay(int n) {
        if (n ==0){
            return "";
        }
        String s = "1";
        while(--n  > 0){
            s = say(s);
        }
        return s;
    }

        public String say(String s) {
            List<int[]> out1 = new ArrayList<>();
            out1.add(new int[2]);
            int[] t = out1.get(out1.size()-1);
            t[0] = s.charAt(0) - '0';
            t[1] = 1;
            for (int i = 1; i < s.length(); i++) {
                if(s.charAt(i) == s.charAt(i-1)){
                    t = out1.get(out1.size()-1);
                    t[1]++;
                }
                else{
                    out1.add(new int[2]);
                    t = out1.get(out1.size()-1);
                    t[0] = s.charAt(i) - '0';
                    t[1] = 1;
                }
            }
            StringBuilder sb = new StringBuilder();
            for (int[] temp :
                    out1) {
                sb.append(""+temp[1]+temp[0]);
            }
            return sb.toString();
        }
}
